package com.yunsom.testdemo.design.iterator;

/**
 * @author Xbao
 * @version 1.0
 * @description
 * @date 2021/3/10 19:25
 */
public class Repository implements Container{

  public String[] names = {"Alan","Bob","Casio","David"};

  @Override
  public Iterator getIterator() {
    return new MyIterator();
  }

  private class MyIterator implements Iterator{

    int index;

    @Override
    public boolean hasNext() {
      if(index < names.length){
        return true;
      }
      return false;
    }

    @Override
    public Object next() {
      if(this.hasNext()){
        return names[index++];
      }
      return null;
    }
  }
}
